package cn.ekuma.odbo.mobile.helper

import androidx.paging.PagedList
import timber.log.Timber

open class PageListBrowsableHelper<T : Any>(private val pageList: PagedList<T>): AbstractBrowableHelper<T>() {

   init {
      //pageList.loadAround(currentIntIndex)
      _itemCount=pageList.size
   }

   /*override fun initHelper() {
      Timber.d("pageList income is:$pageList")
      pageList.loadAround(currentIntIndex)
      _itemCount=pageList.size
   }*/

   override fun moveTo(i: Int) {
      if(currentIntIndex==i||!moveToAble(i))
         return
      currentIntIndex=i
      if(_itemCount>=0&&currentIntIndex<_itemCount-1) {
         currentItem = pageList[currentIntIndex]
         val next=i+1
         if(next>=pageList.loadedCount&&next<_itemCount-1&&pageList[next]==null)
            pageList.loadAround(next)
      }
   }
}